package main.java.Thread;

public class syn {
    public static void main(String[] args) throws InterruptedException {
        syn_seller s1 = new syn_seller();
        syn_seller s2 = new syn_seller();
        syn_seller s3 = new syn_seller();

        s1.start();
        s2.start();
        s3.start();
    }
}


class syn_seller extends Thread {
    static int ticket_num = 100;
    static boolean sellable = true;

    @Override
    public void run() {
        sell();
    }

    public synchronized void sell() {
        while (ticket_num > 0 && sellable){
            try {
                System.out.println(Thread.currentThread().getName() + "卖票一张，还剩" + --ticket_num);
                Thread.sleep(100);

            } catch (InterruptedException e) {
                System.out.println(Thread.currentThread().getName() + "被中断了！！！！");
            }

        }
    }
}

